package com.xyzwps.benchmarks.json;

import org.apache.johnzon.mapper.Adapter;
import org.apache.johnzon.mapper.Mapper;
import org.apache.johnzon.mapper.MapperBuilder;

import java.util.Date;

public class JohnzonUtils implements JsonUtils {

    private static final Mapper mapper = new MapperBuilder()
            .addAdapter(new Adapter<Date, Long>() {
                public Date to(Long b) { return new Date(b); }
                public Long from(Date a) { return a.getTime(); }
            })
            .build();

    @Override
    public String stringify(Object obj) {
        return mapper.writeObjectAsString(obj);
    }

    @Override
    public <T> T parse(String s, Class<T> c) {
        return mapper.readObject(s, c);
    }

    public static final JohnzonUtils INSTANCE = new JohnzonUtils();
}
